﻿
namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Huirui.Cavan.Core.Persistent;
    using Huirui.Cavan.Domain.MainBoundedContext.SystemModule;
    using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
    using Huirui.Cavan.Core.MyLinq;
    using Huirui.Cavan.Core.Extension;

    public class UserAccountSpecification : ISpecification<UserAccount, UserAccountSearch>
    {
        #region ISpecification<UserAccount,UserAccountSearch> Members

        public UserAccountSearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<UserAccount> Members

        public System.Linq.Expressions.Expression<Func<UserAccount, bool>> Expression
        {
            get
            {
                IQueryBuilder<UserAccount> queryBuilder = QueryBuilder.Create<UserAccount>();
                queryBuilder = queryBuilder.NotEquals(ua => ua.IsDeleted, true);

                if (null != SearchParams)
                {
                    if (SearchParams.Name.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(ua => ua.Name, SearchParams.Name);
                    }
                    //if (SearchParams.Password.IsNotEmpty())
                    //{
                    //    queryBuilder = queryBuilder.Equals(ua => ua.Password, SearchParams.Password);
                    //}
                }

                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
